package com.javaspeak.designpatterns.go4.behavioural.state;

/**
 * This is the state object for the Premiere Account Type where the criteria
 * for having one is  determined by the current annual Salary.  This state
 * object will be automatically downgraded to a StandardAccountState if the
 * salary raises below the salary defined in the enum:
 * <p>
 * SalaryGrade.PREMIERE_ACCOUNT.getSalary().
 * <p>
 * Similarly the account will be downloaded further to a
 * StarterAccountState if the salary drops below
 * <p>
 * SalaryGrade.STANDARD_ACCOUNT.getSalary()
 * <p>
 * The other method calls do not result in the State Object being switched
 * for another one.  However the other methods have different method
 * implementations amongst the state objects. For example calling getOverdraft()
 * on a PremierAccountState gives an overdraft of 5000 while calling
 * getOverdraft() on StandardAccountState gives an overdraft of 700.
 *
 * @author John Dickerson
 */
public class PremiereAccountState extends AbstractAccountState {

    /**
     * Constructor
     *
     * @param salary
     * @param balance
     */
    public PremiereAccountState( int salary, float balance ){

        super( salary, balance );
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#setSalary(com.javaspeak.designpatterns.go4.behavioural.state.
     *          StateContext, int)
     */
    @Override
    public void setSalary( StateContext stateContext, int salary ) {

        if ( salary < SalaryGrade.STANDARD_ACCOUNT.getSalary() ){

            stateContext.changeState(
                    new StarterAccountState( salary, this.balance ) );
        }
        else if ( salary < SalaryGrade.PREMIERE_ACCOUNT.getSalary() ){

            stateContext.changeState(
                    new StandardAccountState( salary, this.balance ) );
        }
        else {

            this.salary = salary;
        }
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#getOverdraft()
     */
    @Override
    public int getOverdraft() {

        return 5000;
    }


    /* (non-Javadoc)
     * @see com.javaspeak.designpatterns.go4.behavioural.state.
     *      State#getAccountName()
     */
    @Override
    public String getAccountName() {

        return "Premiere Account";
    }
}
